package com.qf.interfacedemo;

import com.qf.hero.Fightable;

/**
 * abstract 关键字，可以添加在类的前面，作用：当前类就是抽象类了，抽象类不能通过 new 的方式被创建对象
 */
public abstract class Animal implements Flyable,Fireable, Fightable {

    private String breed;

    private String sex;

    private int age;

    // 攻击力
    private int atk;

    // 添加hp属性，用来判断当前对象是否存活
    private int hp;


    public int getAtk() {
        return atk;
    }

    public void setAtk(int atk) {
        this.atk = atk;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public String getBreed() {
        return breed;
    }

    public void setBreed(String breed) {
        this.breed = breed;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }


    public abstract void sleep();

    public abstract void eat();

//    public static abstract  void test1(); // 错误


    public static void test1(){
        System.out.println("test1");
    }

    @Override
    public void fly() {
        System.out.println("动物在飞");
    }

    @Override
    public void fire() {
        System.out.println("动物喷火了");
    }

    @Override
    public boolean isAlive() {
        return hp>0;
    }

    @Override
    public void fight(Fightable enemy) {
        // 计算当前对象造成的伤害值
        int damage = atk;
        // 让敌人受伤
        enemy.takeDamage(damage);
    }

    @Override
    public void takeDamage(int damage) {
        this.hp-=damage;
    }

    @Override
    public void printInfo() {
        System.out.print("breed="+breed+",hp="+hp+",atk="+atk);
        System.out.println();
    }
}
